package com.alorm.core.sqlite.sqlgen;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.alorm.core.exceptions.TypeNotFoundException;

public class Conversion {

	private final static Conversion conversion = new Conversion();
	private Map<String, String> table = new HashMap<String, String>();
	private ArrayList<String> listClassPesr = new ArrayList<String>();

	private Conversion() {

		table.put("int", "INTEGER");
		table.put("String", "TEXT");
		table.put("long", "INTEGER");
		table.put("double", "REAL");
		table.put("Long", "INTEGER");
		table.put("Integer", "INTEGER");

	}

	public void addClassPer(String cNom) {
		listClassPesr.add(cNom);

	}

	public boolean contains(String nType) {

		return table.containsKey(nType);
	}

	public String getTypeSQL(String fType) throws TypeNotFoundException {

		String type = table.get(getClassName(fType));

		if (type != null)
			return type;

		else
			throw new TypeNotFoundException("Le type " + getClassName(fType) + " n'est pas valide !!");

	}

	private String getClassName(String nam) {

		String[] tokens = nam.trim().split("\\.");

		return tokens[tokens.length - 1];

	}

	public static Conversion getConversion() {
		return conversion;
	}

	public ArrayList<String> getListClassPesr() {
		return listClassPesr;
	}

	public void setListClassPesr(ArrayList<String> listClassPesr) {
		this.listClassPesr = listClassPesr;
	}

}
